package com.projeto.persistence;

import com.projeto.infra.business.GenericEntity;
import java.io.Serializable;
import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * The persistent class for the usertable database table.
 *
 */
@Entity
@Table(name = "USERTABLE")
public class User extends GenericEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    private String login;
    private String name;
    private String password;

    @Temporal( TemporalType.TIMESTAMP)
    @Column(name = "CREATE_DT")
    private Date createDt;
    @Temporal( TemporalType.TIMESTAMP)
    @Column(name = "UPDATE_DT")
    private Date updateDt;
    
    //bi-directional many-to-many association to Grouptable
    @ManyToMany(cascade = {CascadeType.PERSIST})
    @JoinTable(
		name = "usergroup", joinColumns = {
        @JoinColumn(name = "LOGIN")
    }, inverseJoinColumns = {
        @JoinColumn(name = "GROUPID")
    })
    private Set<GroupTable> groupTables;

    public User() {
    }

    public String getLogin() {
        return this.login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Set<GroupTable> getGroupTables() {
        return this.groupTables;
    }

    public void setGroupTables(Set<GroupTable> groupTables) {
        this.groupTables = groupTables;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 31 * hash + (this.login != null ? this.login.hashCode() : 0);
        hash = 31 * hash + (this.password != null ? this.password.hashCode() : 0);
        hash = 31 * hash + (this.groupTables != null ? this.groupTables.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final User other = (User) obj;
        if ((this.login == null) ? (other.login != null) : !this.login.equals(other.login)) {
            return false;
        }
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        if ((this.password == null) ? (other.password != null) : !this.password.equals(other.password)) {
            return false;
        }
        if (this.groupTables != other.groupTables && (this.groupTables == null || !this.groupTables.equals(other.groupTables))) {
            return false;
        }
        return true;
    }



    @Override
    public String getId() {
        return this.login;
    }

    @Override
    public void setId(String id) {
        this.login = id;
    }

    public Date getCreateDt() {
        return createDt;
    }

    public void setCreateDt(Date createDt) {
        this.createDt = createDt;
    }

    public Date getUpdateDt() {
        return updateDt;
    }

    public void setUpdateDt(Date updateDt) {
        this.updateDt = updateDt;
    }

    @Override
    public User getCreatedBy() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void setCreatedBy(User createdBy) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public User getUpdatedBy() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void setUpdatedBy(User updatedBy) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}